﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestionEco;

namespace Ecosystème
{
    public partial class PanneauDeControle : Form
    {
        private Case laCaseSelectionnee;

        public PanneauDeControle()
        {
           InitializeComponent();
        }

        #region assesseurs

        public Case LaCaseSelectionnee
        {
            get { return laCaseSelectionnee; }
            set { laCaseSelectionnee = value; }
        }

        #endregion

        public void chargementDuPanneau()
        {
            this.dgvListeEtre.Rows.Clear();
            if (this.LaCaseSelectionnee.Terrain != null)
            {

                lbType.Text = this.LaCaseSelectionnee.Terrain.Type;
                lbEauMax.Text = this.LaCaseSelectionnee.Terrain.Humidite.ToString();
                lbEauRestante.Text = this.LaCaseSelectionnee.Terrain.QteEauActuelle.ToString();
                Image im = null;
                Bitmap img = null;
                if (this.LaCaseSelectionnee.Terrain.Type == "Mer")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\mer.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (this.LaCaseSelectionnee.Terrain.Type == "Plaine")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Plaine.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (this.LaCaseSelectionnee.Terrain.Type == "Forêt")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Foret.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (this.LaCaseSelectionnee.Terrain.Type == "Montagne")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Montagne.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (this.LaCaseSelectionnee.Terrain.Type == "Désert")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Desert.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (img != null)
                    pbTerrain.Image = img;
            }
            Bitmap img2 = null;
            foreach (EtreVivant ev in this.laCaseSelectionnee.ListEVCase)
            {
                img2 = new Bitmap(ev.ImageEtre, 25, 25);
                ImageConverter converter = new ImageConverter();
                dgvListeEtre.Rows.Add(ev.NomEtre, (byte[])converter.ConvertTo(img2, typeof(byte[])));
            }
        }

        private void dgvListeEtre_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >=0)
            {
                foreach (EtreVivant ev in this.laCaseSelectionnee.ListEVCase)
                {
                    if (dgvListeEtre.Rows[e.RowIndex].Cells["Nom"].Value.ToString() == ev.NomEtre)
                    {    
                        lbAtt.Text = ev.Attaque.ToString();
                        lbDeg.Text = ev.Degats.ToString();
                        lbEsq.Text = ev.Esquive.ToString();
                        lbFAct.Text = ev.FaimActuelle.ToString();
                        lbPA.Text = ev.PointsActionActuels.ToString();
                        lbAge.Text = ev.Age.ToString();
                        lbReg.Text = ev.Regen.ToString();
                        lbSAct.Text = ev.SoifActuelle.ToString();
                        lbVAct.Text = ev.VieActuelle.ToString();
                        lbVMax.Text = ev.VieMax.ToString();
                        lbVue.Text = ev.Vue.ToString();
                        if (ev.Sexe)
                        {
                            lbSexe.Text = "Male";
                        }
                        else
                        {
                            lbSexe.Text = "Femelle";
                        }
                    }
                }
            }
        }

        
    }
}
